let mysql = {}
let path = require("path")
/**
 * 用户的api
 */
@get("/api/user");

module.exports =  {
    @get("/login")  // 登录接口
    @get("vp:account,pwd")
     login: async(ctx)=>{
        let account = ctx.account;
        let pwd = md5(ctx.pwd);
        let user = await mysql.table("user").where('account',account).first();
        if(user){
            // 账号存在
            if(user.pwd === pwd){
                // 设置cookie
                user = JSON.parse(JSON.stringify(user))
                delete user.pwd;
                // 设置cookie
                ctx.cookie.set("login_token",user.id)
                return {code:200,message:"登录成功",data:user}
            }else{
                // 密码错误
                return {code:203,message:"密码错误"}
            }
        }else{
            return {code:203,message:"账号不存在"}
        }
    }
}

